<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>Satellite: Satellite/RTC/SPI/spi.h Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  <td id="projectlogo"><img alt="Logo" src="LASAR Logo.png"/></td>
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">Satellite
   &#160;<span id="projectnumber">Revision 55</span>
   </div>
   <div id="projectbrief">Embedded AC Light Control and Bluetooth</div>
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.8.0 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">Satellite/RTC/SPI/spi.h</div>  </div>
</div><!--header-->
<div class="contents">
<a href="spi_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* </span>
<a name="l00002"></a>00002 <span class="comment"> * Copyright (c) 2009 Andrew Smallbone &lt;andrew@rocketnumbernine.com&gt;</span>
<a name="l00003"></a>00003 <span class="comment"> *</span>
<a name="l00004"></a>00004 <span class="comment"> * Permission is hereby granted, free of charge, to any person obtaining a copy</span>
<a name="l00005"></a>00005 <span class="comment"> * of this software and associated documentation files (the &quot;Software&quot;), to deal</span>
<a name="l00006"></a>00006 <span class="comment"> * in the Software without restriction, including without limitation the rights</span>
<a name="l00007"></a>00007 <span class="comment"> * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell</span>
<a name="l00008"></a>00008 <span class="comment"> * copies of the Software, and to permit persons to whom the Software is</span>
<a name="l00009"></a>00009 <span class="comment"> * furnished to do so, subject to the following conditions:</span>
<a name="l00010"></a>00010 <span class="comment"> * </span>
<a name="l00011"></a>00011 <span class="comment"> * The above copyright notice and this permission notice shall be included in</span>
<a name="l00012"></a>00012 <span class="comment"> * all copies or substantial portions of the Software.</span>
<a name="l00013"></a>00013 <span class="comment"> * </span>
<a name="l00014"></a>00014 <span class="comment"> * THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR</span>
<a name="l00015"></a>00015 <span class="comment"> * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</span>
<a name="l00016"></a>00016 <span class="comment"> * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE</span>
<a name="l00017"></a>00017 <span class="comment"> * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</span>
<a name="l00018"></a>00018 <span class="comment"> * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,</span>
<a name="l00019"></a>00019 <span class="comment"> * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN</span>
<a name="l00020"></a>00020 <span class="comment"> * THE SOFTWARE.</span>
<a name="l00021"></a>00021 <span class="comment"> */</span>
<a name="l00022"></a>00022 <span class="preprocessor">#ifndef _spi_h__</span>
<a name="l00023"></a>00023 <span class="preprocessor"></span><span class="preprocessor">#define _spi_h__</span>
<a name="l00024"></a>00024 <span class="preprocessor"></span>
<a name="l00025"></a>00025 <span class="preprocessor">#include &lt;avr/io.h&gt;</span>
<a name="l00026"></a>00026 
<a name="l00027"></a>00027 <span class="preprocessor">#ifdef __cplusplus</span>
<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="keyword">extern</span> <span class="stringliteral">&quot;C&quot;</span>{
<a name="l00029"></a>00029 <span class="preprocessor">#endif</span>
<a name="l00030"></a>00030 <span class="preprocessor"></span>
<a name="l00031"></a>00031 <span class="comment">// create alias for the different SPI chip pins - code assumes all on port B</span>
<a name="l00032"></a><a class="code" href="spi_8h.html#a003fbe87aad5106aed3802d794580bbf">00032</a> <span class="preprocessor"> #define SPI_SS_PIN PORTD5              //CHANGED THIS 3/20/2012 - CSW</span>
<a name="l00033"></a><a class="code" href="spi_8h.html#aee89f642bb559e12db93e9f412ea185e">00033</a> <span class="preprocessor"></span><span class="preprocessor"> #define SPI_SCK_PIN PORTB5</span>
<a name="l00034"></a><a class="code" href="spi_8h.html#a67d2c0b6e0ecbd0351958756e4830172">00034</a> <span class="preprocessor"></span><span class="preprocessor"> #define SPI_MOSI_PIN PORTB3</span>
<a name="l00035"></a><a class="code" href="spi_8h.html#a315722498711fce1e1aa6ea6654385cf">00035</a> <span class="preprocessor"></span><span class="preprocessor"> #define SPI_MISO_PIN PORTB4</span>
<a name="l00036"></a>00036 <span class="preprocessor"></span>
<a name="l00037"></a>00037 <span class="comment">// SPI clock modes</span>
<a name="l00038"></a><a class="code" href="spi_8h.html#a1ec07ad94d5f6276c1c0b41d0550fe52">00038</a> <span class="preprocessor">#define SPI_MODE_0 0x00 </span><span class="comment">/* Sample (Rising) Setup (Falling) CPOL=0, CPHA=0 */</span>
<a name="l00039"></a><a class="code" href="spi_8h.html#af2af9f45539491c9753960535dc20fde">00039</a> <span class="preprocessor">#define SPI_MODE_1 0x01 </span><span class="comment">/* Setup (Rising) Sample (Falling) CPOL=0, CPHA=1 */</span>
<a name="l00040"></a><a class="code" href="spi_8h.html#a8fa3edd8616f8803490c93f09243a612">00040</a> <span class="preprocessor">#define SPI_MODE_2 0x02 </span><span class="comment">/* Sample (Falling) Setup (Rising) CPOL=1, CPHA=0 */</span>
<a name="l00041"></a><a class="code" href="spi_8h.html#a6a091da9f9011457fe28ab25f64c858d">00041</a> <span class="preprocessor">#define SPI_MODE_3 0x03 </span><span class="comment">/* Setup (Falling) Sample (Rising) CPOL=1, CPHA=1 */</span>
<a name="l00042"></a>00042 
<a name="l00043"></a>00043 <span class="comment">// data direction</span>
<a name="l00044"></a><a class="code" href="spi_8h.html#a5a49a9323b5e0f95d8f08cccde5439e6">00044</a> <span class="preprocessor">#define SPI_LSB 1 </span><span class="comment">/* send least significant bit (bit 0) first */</span>
<a name="l00045"></a><a class="code" href="spi_8h.html#adbe0ae38094cacd36ef5bc6d08516ec3">00045</a> <span class="preprocessor">#define SPI_MSB 0 </span><span class="comment">/* send most significant bit (bit 7) first */</span>
<a name="l00046"></a>00046 
<a name="l00047"></a>00047 <span class="comment">// whether to raise interrupt when data received (SPIF bit received)</span>
<a name="l00048"></a><a class="code" href="spi_8h.html#aafaf1f4083ac4fe007ce62dd12724ff7">00048</a> <span class="preprocessor">#define SPI_NO_INTERRUPT 0</span>
<a name="l00049"></a><a class="code" href="spi_8h.html#abcc154757b25dda166dce9045be9ab84">00049</a> <span class="preprocessor"></span><span class="preprocessor">#define SPI_INTERRUPT 1</span>
<a name="l00050"></a>00050 <span class="preprocessor"></span>
<a name="l00051"></a>00051 <span class="comment">// slave or master with clock diviser</span>
<a name="l00052"></a><a class="code" href="spi_8h.html#a943af7f8a98cf5a3f2107ed593215a4b">00052</a> <span class="preprocessor">#define SPI_SLAVE 0xF0</span>
<a name="l00053"></a><a class="code" href="spi_8h.html#aa19f01bd2b4ca43f0f0db772769e6dd5">00053</a> <span class="preprocessor"></span><span class="preprocessor">#define SPI_MSTR_CLK4 0x00 </span><span class="comment">/* chip clock/4 */</span>
<a name="l00054"></a><a class="code" href="spi_8h.html#ad2ca6390ef48b2c620297486e0c5d623">00054</a> <span class="preprocessor">#define SPI_MSTR_CLK16 0x01 </span><span class="comment">/* chip clock/16 */</span>
<a name="l00055"></a><a class="code" href="spi_8h.html#adc5bef0f466f34d6d483500098fb9d34">00055</a> <span class="preprocessor">#define SPI_MSTR_CLK64 0x02 </span><span class="comment">/* chip clock/64 */</span>
<a name="l00056"></a><a class="code" href="spi_8h.html#a1e9dd129ec884cd2ecd26eb445e7799c">00056</a> <span class="preprocessor">#define SPI_MSTR_CLK128 0x03 </span><span class="comment">/* chip clock/128 */</span>
<a name="l00057"></a><a class="code" href="spi_8h.html#a58e492986b1839ae5ed43e7e666059b4">00057</a> <span class="preprocessor">#define SPI_MSTR_CLK2 0x04 </span><span class="comment">/* chip clock/2 */</span>
<a name="l00058"></a><a class="code" href="spi_8h.html#aa9ffd89e575f13561ba82a516cb0de51">00058</a> <span class="preprocessor">#define SPI_MSTR_CLK8 0x05 </span><span class="comment">/* chip clock/8 */</span>
<a name="l00059"></a><a class="code" href="spi_8h.html#a1721eae25c64517d5638fa590e85f0e6">00059</a> <span class="preprocessor">#define SPI_MSTR_CLK32 0x06 </span><span class="comment">/* chip clock/32 */</span>
<a name="l00060"></a>00060 
<a name="l00061"></a>00061 
<a name="l00062"></a>00062 
<a name="l00063"></a>00063 <span class="comment">// setup spi</span>
<a name="l00064"></a>00064 <span class="keywordtype">void</span> <a class="code" href="spi_8c.html#a718fd95b673032c496cb31b73e589ffb">setup_spi</a>(uint8_t mode,   <span class="comment">// timing mode SPI_MODE[0-4]</span>
<a name="l00065"></a>00065                <span class="keywordtype">int</span> dord,             <span class="comment">// data direction SPI_LSB|SPI_MSB</span>
<a name="l00066"></a>00066                <span class="keywordtype">int</span> interrupt,        <span class="comment">// whether to raise interrupt on receive</span>
<a name="l00067"></a>00067                uint8_t clock); <span class="comment">// clock divisor</span>
<a name="l00068"></a>00068 
<a name="l00069"></a>00069 <span class="comment">// disable spi</span>
<a name="l00070"></a>00070 <span class="keywordtype">void</span> <a class="code" href="spi_8c.html#a7e429871e44a553f1120b5cc91d06a52">disable_spi</a>(<span class="keywordtype">void</span>);
<a name="l00071"></a>00071 
<a name="l00072"></a>00072 <span class="comment">// send and receive a byte of data (master mode)</span>
<a name="l00073"></a>00073 uint8_t <a class="code" href="spi_8c.html#a6c4c47d9a595f6208f146fa4d75cff4d">send_spi</a>(uint8_t out);
<a name="l00074"></a>00074 
<a name="l00075"></a>00075 <span class="comment">// receive the byte of data waiting on the SPI buffer and</span>
<a name="l00076"></a>00076 <span class="comment">// set the next byte to transfer - for use in slave mode</span>
<a name="l00077"></a>00077 <span class="comment">// when interrupts are enabled.</span>
<a name="l00078"></a>00078 uint8_t <a class="code" href="spi_8c.html#abeca4d0f0313558d181d13cef1869f48">received_from_spi</a>(uint8_t out);
<a name="l00079"></a>00079 
<a name="l00080"></a>00080 <span class="preprocessor">#ifdef __cplusplus</span>
<a name="l00081"></a>00081 <span class="preprocessor"></span>} <span class="comment">// extern &quot;C&quot;</span>
<a name="l00082"></a>00082 <span class="preprocessor">#endif</span>
<a name="l00083"></a>00083 <span class="preprocessor"></span>
<a name="l00084"></a>00084 <span class="preprocessor">#endif</span>
<a name="l00085"></a>00085 <span class="preprocessor"></span>
</pre></div></div><!-- contents -->


<hr class="footer"/><address class="footer"><small>
Generated on Thu Apr 19 2012 16:20:24 for Satellite by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.0
</small></address>

</body>
</html>
